# -*- coding: utf-8 -*-
#  @Time    : 2021/6/22 21:12
#  @Author  : Ben
#  @File    : hdshow.py
import pandas as pd
import numpy as np
from pyecharts import options as opts
from pyecharts.charts import Map, Geo, Pie, WordCloud


data = pd.read_csv("today_province_2021_06_22.csv")
# 查看该数据的头五行部分，初步了解
data.head()
# 填充空值
data = data.fillna(0)
# 查看填充后数据的最后五行
data.tail()
print(data)
# 将提取的数据进行排序
total_data = data[["name", "total_confirm"]].sort_values(by="total_confirm", ascending=False)
# total_data[:5]
print(total_data)

map = (
    Map(opts.InitOpts(width="950px", height="950px", page_title="China"))
        .add("china", [list(z) for z in zip(total_data["name"], total_data["total_confirm"])])
        .set_global_opts(
        title_opts=opts.TitleOpts(title="中国各省新冠确诊人数图"),
        legend_opts=opts.LegendOpts(is_show=False),
        visualmap_opts=opts.VisualMapOpts(
            type_="color",
            min_=np.min(total_data["total_confirm"].tolist()),
            max_=np.max(total_data["total_confirm"].tolist()),
            range_text=["最高", "最低"], is_piecewise=True,
            split_number=6,
            pieces=[{"min": 0, "max": 100, "label": "< 100", "color": "red"},
                    {"min": 100, "max": 500, "label": "100 - 500", "color": "blue"},
                    {"min": 500, "max": 1000, "label": "500 - 1000", "color": "grey"},
                    {"min": 1000, "max": 1100, "label": "1000 - 1100", "color": "black"},
                    {"min": 1100, "max": 1200, "label": "1100 - 1200", "color": "orange"},
                    {"min": 1200, "label": "> 1200", "color": "purple"}]))
        .render("china.html")
)

pie = (
    Pie(opts.InitOpts(width="950px", height="950px", page_title="China"))
     .add("china",[list(z) for z in zip(total_data["name"], total_data["total_confirm"])])
     .set_global_opts(
        title_opts=opts.TitleOpts(title="中国各省新冠确诊人数饼图"))
     .render("china_pie.html")
)

wordcloud=(
    WordCloud(opts.InitOpts(width="500px", height="500px", page_title="China"))
    .add(series_name="china",data_pair=[list(z) for z in zip(total_data["name"], total_data["total_confirm"])],shape="circle",word_gap=25,rotate_step=45,width="1000px",height="1000px")
    .set_global_opts(
        title_opts=opts.TitleOpts(title="中国各省新冠确诊人数词云"))
    .render("china_wordcloud.html")
)